var app = getApp();
Page({
  data: {
    item: [],
    sum: 0,
    PointItem: [],
    touchEnd: 0,
    touchStart: 0,
    checked: 0,
    isAll:false
  },

  touchStart: function (e) {
    var that = this;
    that.setData({
      touchStart: e.timeStamp
    })
  },

  touchEnd: function (e) {
    var that = this;
    that.setData({
      touchEnd: e.timeStamp
    })
  },

  pressTap: function (e) {
    var postid = e.currentTarget.dataset.postid
    var that = this;
    var touchTime = that.data.touchStart - that.data.touchEnd;
    if (touchTime >= 600) { //自定义长按时长，单位为ms
      wx.navigateTo({
        url: '/pages/mark_2/mark_2?id=' + postid,
      })
      app.globalData.pass = this.data.item
      that.setData({
        touchEnd: 0,
        touchStart: 0
      })
    } if (touchTime < 600) {
      that.setData({
        touchEnd: 0,
        touchStart: 0
      })
    }
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '录取名单'
    })
    var a = 0
    var i
    var items = app.globalData.data
    var item = []
    for (i = 0; i < app.globalData.sum; i++) {
      if (items[i].isPass1 == 1) {
        if (items[i].isUsed2 == 0 && items[i].isUsed1 == 1 && items[i].isUsed == 1 && items[i].score >= 60) {
          item.push(items[i])
          a++
        }
      } else if (items[i].isPass2 == 1) {
        if (items[i].isUsed2 == 0 && items[i].isUsed1 == 1 && items[i].isUsed == 1 && items[i].score >= 60) {
          item.push(items[i])
          a++
        }
      }
    }
    this.setData({
      item: item,
      sum: a,
      touchEnd: 0,
      touchStart: 0,
    })
  },

  OnIsSendTap: function (event) {
    wx.redirectTo({
      url: '/pages/pass_1/pass_1',
    })
  },

  PointTap: function (e) {
    var postId = e.currentTarget.dataset.postid
    let that = this
    let item = this.data.item
    item[postId].isPoint2 = !item[postId].isPoint2
    // 控制红点的显示
    var i, a = 0
    var PointItem = []
    for (i = 0; i < this.data.sum; i++) {
      if (item[i].isPoint2 == true) {
        PointItem.push(item[i])
        a++
      }
    }
    that.setData({
      item: item,
      PointItem: PointItem,
      checked: a
    })
  },

  OnPass_FinishTap: function (event) {
    wx.redirectTo({
      url: '/pages/message/message?id=' + 1,
    })
    var that = this
    app.globalData.checked = that.data.checked
    app.globalData.list = this.data.PointItem
    
  },

  OnatAllTap: function (e) {
    var that = this
    var items = this.data.item
    var i
    var a = 0
    var PointItem = []
    for (i = 0; i < this.data.sum; i++) {
      if (that.data.isAll == false) {
        if (items[i].isPoint2 == false) {
          items[i].isPoint2 = !items[i].isPoint2
        }
      } else {
        if (items[i].isPoint2 == true) {
          items[i].isPoint2 = !items[i].isPoint2
        }
      }
      if (items[i].isPoint2 == true) {
        a++
        PointItem.push(items[i])
      }
    }
    that.setData({
      isAll: !this.data.isAll,
      item: items,
      checked: a,
      PointItem: PointItem
    })
  },

})